package com.shilan.administrator.qintfm.factory;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.shilan.administrator.qintfm.fragment.tablayoutFragment.AnchorFragment;
import com.shilan.administrator.qintfm.fragment.tablayoutFragment.BroadcastFragment;
import com.shilan.administrator.qintfm.fragment.tabhostFragment.MineFragment;
import com.shilan.administrator.qintfm.fragment.tablayoutFragment.RecommendFragment;

/**
 * Created by dllo on 16/1/12.
 */
public class FragmentFactory  {

    private  static SparseArray<Fragment> fragmentMap = new SparseArray<>();

    public  static Fragment createFragment(int position){
        Fragment f = fragmentMap.get(position);
        if (f ==null){
            switch (position){
                case 0:
                    f = new RecommendFragment();
                    break;
                case 1:
                    f = new BroadcastFragment();
                    break;
                case 2:
                    f = new AnchorFragment();
                    break;
                case 3:
                    f = new MineFragment();
                    break;
            }
            fragmentMap.put(position,f);
        }
        return  f;
    }
}
